<template>
  <div class="mapBox">
    <div id="map" ref="mapElement"></div>
    <div class="header">
      <topCom />
    </div>
    <div class="aside">
      <tabIndex />
    </div>
    <div class="footer">
      <footCom />
    </div>
    <div class="toolbar">
      <toolbar />
    </div>
  </div>
</template> 
    <script setup>
import { onMounted, ref, defineAsyncComponent, onUnmounted } from 'vue'
import topCom from '../layer/header.vue'
import tabIndex from './components/aside/index.vue'
import toolbar from './components/toolbar/index.vue'
import footCom from './components/footer.vue'
import map3d from './js/test'
import { useMapStoreStore } from '../stores'
import { useRoute, useRouter } from 'vue-router'
import { test12, createPointAndToView ,add4490,loadInitView} from '../api/gis3d/maputils'
import { initCircleFadeMaterialProperty } from '../api/gis3d/Material'
import config from '../config/index'
const route = useRoute()
const store = useMapStoreStore()
const data = JSON.parse(route.query.data)

store.eqid = data.id
store.earthquakeInfo = data

const mapElement = ref(null)
const initEarthQuake = ()=>{
  viewer.entities.add({
    zIndex: 9999999,
    position: Cesium.Cartesian3.fromDegrees(
      store.earthquakeInfo.longitude,
      store.earthquakeInfo.latitude,
      0
    ), // 经纬度坐标
     billboard: {
            image:  '/static/assets/3d/zz.png', // 图片的路径  
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,// 设置贴地
            color: Cesium.Color.fromCssColorString('rgba(255,255,255,1)'), // 使用rgba设置透明度，这里是70%透明的白色，可调整最后一个参数
            verticalOrigin: Cesium.VerticalOrigin.CENTER,
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER
        },
    // point: {
    //   heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, // 设置贴地
    //   color: Cesium.Color.fromCssColorString('#ff0000'), // 设置点的颜色为绿色（#00FF00）
    //   pixelSize: 20,
    //   eyeOffset: new Cesium.Cartesian3(0.0, 0.0, -10.0)
    // }
  })
  loadInitView(store.eqid,store.earthquakeInfo.version)
}

onMounted(async () => {
  window.map3d = map3d
  await map3d.initViewer('map',[config.TDTTK])
  //  initMark()
  // map3d.isShowTerrin(false) //关闭地形
  // map3d.depthTest(true);
  map3d.setBaseMap('天地图影像')
  store.$patch({ isInitCesium: true })
  // add4490()
// console.log(viewer.scene);
// var scheduler = Cesium.Resource.scheduler;
// Cesium.RequestScheduler.maximumRequestsPerServer = 18
initEarthQuake()
//     // map3d.depthTest(true);
// viewer.scene.mapProjection.projection  =new Cesium.WebMercatorProjection()
})

onUnmounted(() => {
  store.initStore();
   if (viewer) {
      viewer.entities.removeAll();
      viewer.imageryLayers.removeAll();
      viewer.dataSources.removeAll();
      let gl = viewer.scene.context._originalGLContext;
      gl.canvas.width = 1;
      gl.canvas.height = 1;
      viewer.destroy();
      gl.getExtension("WEBGL_lose_context").loseContext();
      gl = null;
      window.viewer = null;
    }
})
</script>
  <style lang="scss">
.scroll-b {
  &::-webkit-scrollbar {
    width: 6px;
    height: 8px;
  }
  &::-webkit-scrollbar-button {
    display: none;
  }
  &::-webkit-scrollbar-thumb {
    background: #01c2ff;
    cursor: pointer;
    border-radius: 4px;
  }
  &::-webkit-scrollbar-corner {
    display: none;
  }
  &::-webkit-resizer {
    display: none;
  }
}
</style>
<style scoped>
.mapBox {
  position: relative;
}
#map,
.mapBox {
  width: 100vw;
  height: 100vh;
}
#map {
  position: absolute;
  top: 0;
  left: 0;
}
.header {
  position: absolute;
  top: 0;
  width: 100%;
  height: 9.2592vh;
  z-index: 1;
}
.aside {
  position: absolute;
  top: 9.2592vh;
  left: 0px;
}
.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  min-width: 1000px;
  height: 30px;
  background: rgba(63, 62, 62, 0.8);
  box-shadow: 0px -4px 10px 0px rgba(0, 65, 133, 0.3);
  z-index: 1;
}
.toolbar {
  position: absolute;
  right: 20px;
  top: 8vh;
  z-index: 11;
}
.comview {
  position: absolute;
  right: 20px;
  top: 17.5vh;
  height: 76vh;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  /* flex-wrap: wrap; */
}
</style>
    
    